// pages/details/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:'',
    TabCur:0,
    tabNav:['办公设备类','房产类','运输设备类','机械设备类'],
    idx : 0
  },
  
  // tabnav点击事件
  tabSelect:function(e){
    let index = e.currentTarget.dataset.id;
    // console.log(e.currentTarget.dataset.id);
    this.setData({
      idx: index,
      TabCur:e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },
  fangchan:function(b){//点击详情
    console.log(b);
    let id=b.currentTarget.dataset.id
    console.log(id);
    
    wx.navigateTo({
      url: '/pages/cesha/cesha?id='+JSON.stringify(id),
    })
  },
  yunshu:function(b){//点击详情
    console.log(b);
    let id=b.currentTarget.dataset.id
    console.log(id);
    wx.navigateTo({
      url: '/pages/ceshb/ceshb?id='+JSON.stringify(id),
    })
  },
  dianji:function(b){//点击详情
    console.log(b);
    let id=b.currentTarget.dataset.id
    console.log(id);
    
    wx.navigateTo({
      url: '/pages/ceshi/ceshi?id='+JSON.stringify(id),
    })
  },
  jixie:function(b){//点击详情
    console.log(b);
    let id=b.currentTarget.dataset.id
    console.log(id);
    
    wx.navigateTo({
      url: '/pages/ceshc/ceshc?id='+JSON.stringify(id),
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  // 办公设备类
  equipment:function(){
    var that = this
    console.log(that.data.openid);
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=equipment',
      data:{
        openid:that.data.openid
      },
      method:'POST',
      header: {
        "Accept": "application/json"
      },
      success:function(res){
        // console.log(res);
        that.setData({
          list:res.data
        })
      }
    })
  },
  // 房产类
  house:function(){
    var that = this
    console.log(that.data.openid);
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=house',
      data:{
        openid:that.data.openid
      },
      method:'POST',
      header: {
        "Accept": "application/json"
      },
      success:function(res){
        // console.log(res);
        that.setData({
          hist:res.data
        })
      }
    })
  },
  // 运输设备类
  transportation:function(){
    var that = this
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=transportation',
      data:{
        openid:that.data.openid
      },
      method:'POST',
      header: {
        "Accept": "application/json"
      },
      success:function(res){
        // console.log(res.data);
        that.setData({
          tist:res.data
        })
      }
    })
  },
  // 机械设备类
  mechanical:function(){
    var that = this
    wx.request({
      url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=mechanical',
      data:{
        openid:that.data.openid
      },
      method:'POST',
      header: {
        "Accept": "application/json"
      },
      success:function(res){
        // console.log(res.data);
        that.setData({
          mist:res.data
        })
      }
    })
  },
  onTabItemTap() {
    this.bar();
  },
  bar:function(){
    let self = this
    if (!wx.getStorageSync('open')) {
      wx.showModal({
        title: '提示',
        content: '账号尚未登录，请先登录账号',
        success: res => {
          if (res.confirm) {
            // console.log(res.confirm)
            wx.reLaunch({
              url: '/pages/my/my',
            })
          } else if (res.cancel) {
            wx.reLaunch({
              url: '/pages/logs/logs'
            })
          }
        }
      })
    }
  },
  onLoad: function (options) {
    this.bar();
    var that = this;
    wx.getStorage({
      key: 'open',
      success:(res)=>{
        // console.log(res.data);
        that.setData({
          openid:res.data,
        })
        // that.onShow();
        console.log(that.data.openid);
        this.equipment();
        this.house();
        this.transportation();
        this.mechanical();
      }
    })
  },
// 办公设备类删除
e_del:function(e){
  var that = this;
  wx.showModal({
    title: '提示',
    content: '您确定删除吗？',
    success (res) {
      if (res.confirm) {
        wx.request({
          url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=equ_del',
          method:'POST',
          data:{id:e.currentTarget.dataset.id},
          header: {
            "Accept": "application/json"
          },
          success:function(res){
         
              console.log(res.data.code);
              if(res.data.code==1){
                wx.showModal({
                  title: '提示',
                  content: '删除成功',
                  success: function (sm) {
                    that.equipment();
                    if (sm.confirm) {
                        // 用户点击了确定 可以调用删除方法了
                        // console.log()
                      } else if (sm.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
              }
          }
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},

// 房产类删除
h_del:function(e){
  var that = this;
  console.log(e);
  wx.showModal({
    title: '提示',
    content: '您确定删除吗？',
    success (res) {
      if (res.confirm) {
        wx.request({
          url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=house_del',
          method:'post',
          data:{id:e.currentTarget.dataset.id},
          header: {
            "Accept": "application/json"
          },
          success:function(res){
              console.log(res.data.code);
              if(res.data.code==1){
                wx.showModal({
                  title: '提示',
                  content: '删除成功',
                  success: function (sm) {
                    that.house();
                    if (sm.confirm) {
                        // 用户点击了确定 可以调用删除方法了
                        console.log()
                      } else if (sm.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
              }
          }
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},
// 运输设备类删除
t_del:function(e){
  var that = this;
  console.log(e);
  wx.showModal({
    title: '提示',
    content: '您确定删除吗？',
    success (res) {
      if (res.confirm) {
        wx.request({
          url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=trans_del',
          method:'post',
          data:{id:e.currentTarget.dataset.id},
          header: {
            "Accept": "application/json"
          },
          success:function(res){
              console.log(res.data.code);
              if(res.data.code==1){
                wx.showModal({
                  title: '提示',
                  content: '删除成功',
                  success: function (sm) {
                    that.transportation();
                    if (sm.confirm) {
                        // 用户点击了确定 可以调用删除方法了
                        console.log()
                      } else if (sm.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
              }
          }
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},
// 机械设备类删除
m_del:function(e){
  var that = this;
  console.log(e);
  wx.showModal({
    title: '提示',
    content: '您确定删除吗？',
    success (res) {
      if (res.confirm) {
        wx.request({
          url: 'http://81.68.242.50/index.php/admin/ifi/index?cist=mechanical_del',
          method:'post',
          data:{id:e.currentTarget.dataset.id},
          header: {
            "Accept": "application/json"
          },
          success:function(res){
              console.log(res);
              if(res.data.code==1){
                wx.showModal({
                  title: '提示',
                  content: '删除成功',
                  success: function (sm) {
                    that.mechanical();
                    if (sm.confirm) {
                        // 用户点击了确定 可以调用删除方法了
                        console.log()
                      } else if (sm.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
              }
          }
        })
      } else if (res.cancel) {
        console.log('用户点击取消')
      }
    }
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})